package com.lc.user.express.preferentialactivity;

import android.os.Bundle;
import android.util.Log;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.lc.user.express.BaseSecondActivity;
import com.lc.user.express.R;
import com.lc.user.express.httpserver.Net;
import com.lc.user.express.utils.GetToast;
import com.lc.user.express.view.dialog.ProgressDialog;


/**
 * Created by Administrator on 2016/4/25. 优惠活动详情
 */
public class ActivityWebActivity extends BaseSecondActivity {
    private WebView wView;
    private ProgressDialog dialog = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_web);
        initView();
    }

    private void initView() {
        setTitle(getIntent().getStringExtra("title"));
        wView = (WebView) findViewById(R.id.webview);
        WebSettings wSet = wView.getSettings();
        wSet.setJavaScriptEnabled(true);
        wSet.setDefaultTextEncodingName("UTF-8");

        if (wView != null) {
            wView.setWebViewClient(new WebViewClient() {
                @Override
                public void onPageFinished(WebView view, String url) {
                    dialog.dismiss();

                }

                @Override
                public void onReceivedError(WebView view, int errorCode,
                                            String description, String failingUrl) {
                    // TODO Auto-generated method stub
                    super.onReceivedError(view, errorCode, description, failingUrl);
                    GetToast.useString(cnt, "加载失败");
                }
            });

            Log.i("lll", "==" + Net.SERVER + Net.WEB_PREFERENTIAL_ACTIVITY + "?id=" + getIntent().getStringExtra("id"));

            loadUrl(Net.SERVER + Net.WEB_PREFERENTIAL_ACTIVITY + "?id=" + getIntent().getStringExtra("id"));


        }
    }

    public void loadUrl(String url) {
        if (wView != null) {
            wView.loadUrl(url);
            dialog = new ProgressDialog(cnt, R.style.AppDialog);
            dialog.show();
        }
    }

    @Override
    protected void onDestroy() {

        // TODO Auto-generated method stub
        super.onDestroy();
        if (dialog != null) {
            dialog.dismiss();
        }
    }
}
